window.loglist = [];

define([
    "jquery",
    "help"
], function ($) {

    function getDate() {
        var dat = new Date;//生成日期
        var year = dat.getFullYear();//取得年
        var month = dat.getMonth() + 1;    //取得月,js从0开始取,所以+1
        var date1 = dat.getDate(); //取得天
        var hour = dat.getHours();
        hour = (hour < 10 ? "0" : "") + hour;//取得小时
        var minutes = dat.getMinutes();
        minutes = (minutes < 10 ? "0" : "") + minutes;///取得分钟
        var second = dat.getSeconds();
        second = (second < 10 ? "0" : "") + second;//取得秒
        var haomiao = dat.getMilliseconds();
        haomiao = (haomiao < 100 ? ((haomiao < 10 ? "00" : "0")) : "") + haomiao;//取得秒
        dat = undefined;
        return year + "-" + month + "-" + date1 + " " + hour + ":" + minutes + ":" + second + " " + haomiao;
    }

    var logContent = $("#log .content");

    window.console.log = function (base) {
        return function () {
            if (loglist.length > 120)
                loglist.shift();
            var str = "[" + getDate() + "] ";
            var res = str + Array.prototype.slice.apply(arguments).join(",");
            loglist.push(res);
            if (window.isDebug && window.isOpenLog) {
                if (logContent.children("p").length > 30)
                    logContent.children("p:first").remove();
                $("<p></p>").html(res).appendTo(logContent);
                //base.apply(window, [str].concat(arguments));
                base.call(window, res);
            }
        }
    }(console.log);

    $("#log .button").click(function () {
        window.isOpenLog = !window.isOpenLog;
        if (window.isDebug && window.isOpenLog) {
            $(logContent).show();
        } else {
            $(logContent).hide();
        }
    });

    return this;
});